<%@ page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="ctx" value="${pageContext['request'].contextPath}" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户注册 -- ${applicationScope.sysconfig.system_name }</title>
<SCRIPT type="text/javascript" src="${ctx }/static/js/jquery.min.js"></SCRIPT>
	<!-- bootstrap -->
	<link rel="stylesheet" type="text/css" media="screen"
		href="${ctx }/static/bootstrap/css/bootstrap.css">
	<link rel="stylesheet" type="text/css" media="screen"
		href="${ctx }/static/bootstrap/css/bootstrap-responsive.css">
<STYLE type="text/css">
</STYLE>
<SCRIPT type="text/javascript">
var check_pwd = function() {
	if( $("#pwd").val() != $("#repwd").val() ){
		var msg = $("#msg");
		msg.html("请确保两次输入密码一致");
		setTimeout(function() {
			msg.html("");
		}, 1500);
	}
}
var check_exist = function(type) {
	var val;
	var params;
	if(type == 1) {
		val = $("#username").val();
		params = { v:val, type:1};
	} else {
		val = $("#email").val();
		params = { v:val, type:0};
	}
	if(val.length == 0) {return ;}
	$.post("${ctx}/user/exist", params, function(data){
		if(data.flag == true) {
			alert(val + "已经存在~");
		}
	}, 'json');
}
var check_form = function() {
	var u = $("#username").val().trim();
	var pwd = $("#pwd").val().trim();
	var repwd = $("#repwd").val().trim();
	var email = $("#email").val().trim();
	if(u == "" || pwd == "" || email == "" || pwd != repwd) {
		alert("请填写完整信息！");
	}
}
</SCRIPT>
</head>
<body>
<c:if test="${msg != null }">
<script type="text/javascript">
	alert("${msg}");
</script>
</c:if>
<div class="container">
	<br/>
	<div class="row">
		<div class="span3">&nbsp;</div>
		<div class="span5 well" id="login">
			<FIELDSET class="form-horizontal">
				<legend>用户注册</legend>
				<form id="loginForm" action="${ctx }/user/regist" method="post">
					<input type="hidden" name="inviter" value="${param.inviter }"/>
					<div class="control-group">
						<LABEL class="control-label">用户名：</LABEL>
						<div class="controls">
							<input class="xlarge" type="text" id="username" name="username" onblur="check_exist(1)"/> *
						</div>
					</div>
					<div class="control-group">
						<LABEL class="control-label">邮　箱：</LABEL>
						<div class="controls">
							<input class="xlarge" type="text" id="email" name="email" onblur="check_exist(0)"/> *
						</div>
					</div>
					<div class="control-group">
						<LABEL class="control-label">密　码：</LABEL>
						<div class="controls">
							<input class="xlarge" type="password" id="pwd" name="password"/> *
						</div>
					</div>
					<div class="control-group">
						<LABEL class="control-label">重　复：</LABEL>
						<div class="controls">
							<input class="xlarge" type="password" id="repwd" name="repassword" onblur="check_pwd()"/>
						</div>
					</div>
					<div class="control-group">
						<LABEL class="control-label">昵　称：</LABEL>
						<div class="controls">
							<input class="xlarge" type="text" name="nick"/>
						</div>
					</div>
					<div class="control-group">
						<LABEL class="control-label">&nbsp;</LABEL>
						<div class="controls">
							<input type="checkbox" onclick="$('#reg_btn').toggle()" />我已阅读并接受<a href="${ctx }/user/_reg_protocol" target="_blank">《乐淘淘用户协议》</a>
						</div>
					</div>
					<div class="form-actions btn-groups">
						<input class="btn btn-large btn-success" id="reg_btn" type="submit" value="注册" onclick="check_form()" style="display:none;"/>
						<a class="btn btn-large" href="${ctx }/user/_login">登录</a>
					</div>
				</form>
			</FIELDSET>
		</div>
	</div>
</div>
</body>
</html>